class Solution {
public:
    double p(double x, int n)
    {
        if(n==0)
            return 1.0;
        double res = p(x, n/2);
        return n%2 ? res*res*x : res*res;
    }
    double myPow(double x, int n) {
        return n>0 ? p(x,n) : 1/p(x,n);
    }
};

class Solution {
public:
    double myPow(double x, int n) {
        double res = 1.0;
        int flag = n;
        while(n!=0)
        {
            if(n%2)
                res = res * x;
            x = x * x;
            n = n / 2;
        }

        return flag>0 ? res : 1/res;
    }
};